package sort;
//插入排序
public class insertion {
    public static void sort(Comparable[] a ){
        for (int i = 0; i<a.length-1; i ++){
            for (int j = i+1; j >0; j--){
                if (grate(a[j],a[j-1])){
                    exch(a,j,j-1);
                }
            }
        }
    }
    //判断两个数值的大小
    private static Boolean grate(Comparable x, Comparable y){
        return x.compareTo(y) <0;
    }
    //交换两个元素的位置
    private static void exch(Comparable[] a, int i ,int j){
        Comparable tem = a[i];
        a[i] = a[j];
        a[j] = tem;
    }
}
